﻿<%@ Page Title="Edit User" Language="C#" MasterPageFile="~/App_MasterPages/Aquarius.Master"
    AutoEventWireup="true" CodeBehind="EditUser.aspx.cs" Inherits="PepsiCo.UI.EditUser" %>

<asp:Content ID="Content1" ContentPlaceHolderID="CssContent" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ScriptContent" runat="server">
    <script type="text/javascript">
        $(document).ready(function () {
            $('#<%=ddlStaff.ClientID%>').combobox({
                select: function (event, ui) {
                    $(this).trigger('change');
                }
            });
            $("#ui-id-1").change(function () {
                alert($(this).val());
            });
        });
        function CheckExitsUses(obj) {
            var check = $("#check");
            $.ajax({
                type: "POST",
                url: "WebService.asmx/CheckExistUser",
                data: "{'username':" + JSON.stringify(obj.value) + "}",
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                beforeSend: function () {
                    check.html("<img src='images/loading.gif' alt='Loading...'/>");
                },
                success: function (data) {
                    check.html("");
                    if (data.d == true) {
                        check.html("<span style='color:red'>User name allready exists</span>");
                    }
                }
            });
        }
        function CheckFullInfor() {
            if ($.trim($(".custom-combobox input").val()) == "") {
                $("#staffRequired").html("Staff is required");
                return false;
            }
        }

        function getStaffInfo(staffID) {
            //var param = staffID;
            $.ajax({
                type: "POST",
                url: "WebService.asmx/GetStaffByID",
                data: "{'staffId':" + JSON.stringify(staffID) + "}",
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                success: function (data) {
                    $("#<%=txtStaffName.ClientID%>").val(data.d.StaffName);
                    $("#<%=txtUnitName.ClientID%>").val(data.d.UnitName);
                    $("#<%=txtStaffType.ClientID%>").val(data.d.StaffTypeName);
                    $("#<%=txtStaffLevel.ClientID%>").val(data.d.StaffLevel);
                }
            });
        }
    </script>
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="MainContent" runat="server">
    <div class="span4">
        <div class="head">
            <div class="isw-list">
            </div>
            <h1>
                Account Information</h1>
            <div class="clear">
            </div>
        </div>
        <div class="block-fluid ui-corner-all" style="overflow: auto; padding: 10px">
            <p>
                <asp:Label ID="UserNameLabel" runat="server" AssociatedControlID="txtUserName">User Name:</asp:Label>
                <asp:TextBox ID="txtUserName" runat="server" onblur="CheckExitsUses(this);" /><br />
                <asp:RequiredFieldValidator ID="UserNameRequired" runat="server" ControlToValidate="txtUserName"
                    ForeColor="Red" ErrorMessage="UserName is required." Display="Dynamic" ToolTip="UserName is required."
                    ValidationGroup="RegisterUserValidationGroup" />
                <span id="check"></span>
            </p>
            <asp:Panel ID="pnlPassword" runat="server">
                <p>
                    <asp:Label ID="PasswordLabel" runat="server" AssociatedControlID="txtPassword">Password:</asp:Label>
                    <asp:TextBox ID="txtPassword" runat="server" TextMode="Password"></asp:TextBox><br />
                    <asp:RequiredFieldValidator ID="PasswordRequired" runat="server" ControlToValidate="txtPassword"
                        ForeColor="Red" ErrorMessage="Password is required." Display="Dynamic" ToolTip="Password is required."
                        ValidationGroup="RegisterUserValidationGroup" />
                </p>
                <p>
                    <asp:Label ID="ConfirmPasswordLabel" runat="server" AssociatedControlID="txtConfirmPassword">Confirm Password:</asp:Label>
                    <asp:TextBox ID="txtConfirmPassword" runat="server" TextMode="Password"></asp:TextBox><br />
                    <asp:RequiredFieldValidator ControlToValidate="txtConfirmPassword" ForeColor="Red"
                        Display="Dynamic" ErrorMessage="Confirm Password is required." ID="ConfirmPasswordRequired"
                        runat="server" ToolTip="Confirm Password is required." ValidationGroup="RegisterUserValidationGroup" />
                    <asp:CompareValidator ID="PasswordCompare" runat="server" ControlToCompare="txtPassword"
                        ControlToValidate="txtConfirmPassword" ForeColor="Red" Display="Dynamic" ErrorMessage="The Password and Confirmation Password must match."
                        ValidationGroup="RegisterUserValidationGroup" />
                </p>
            </asp:Panel>
            <p>
                <asp:Label ID="EmailLabel" runat="server" AssociatedControlID="txtEmail">E-mail:</asp:Label>
                <asp:TextBox ID="txtEmail" runat="server" /><br />
                <asp:RequiredFieldValidator ID="EmailRequired" runat="server" ControlToValidate="txtEmail"
                    ForeColor="Red" ErrorMessage="E-mail is required." Display="Dynamic" ToolTip="E-mail is required."
                    ValidationGroup="RegisterUserValidationGroup" />
                <asp:RegularExpressionValidator ID="EmailEpxression" runat="server" ControlToValidate="txtEmail"
                    ForeColor="Red" ErrorMessage="E-mail is invalid." Display="Dynamic" ValidationGroup="RegisterUserValidationGroup"
                    ValidationExpression="^[a-z0-9_]+(?:\.[a-z0-9]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])$" />
            </p>
            <p>
                <asp:Label ID="lbStaff" runat="server" AssociatedControlID="ddlStaff">Staff:</asp:Label>
                <asp:DropDownList ID="ddlStaff" runat="server" CssClass="combo" onchange="getStaffInfo($(this).val()); return false;" />
                <br />
                <asp:RequiredFieldValidator ControlToValidate="ddlStaff" ForeColor="Red" Display="Dynamic"
                    ErrorMessage="Unit is required." ID="UnitRequired" runat="server" ToolTip="Unit is required."
                    ValidationGroup="RegisterUserValidationGroup" />
                <span id="staffRequired" style="color: Red"></span>
            </p>
            <div class="dr">
                <span></span>
            </div>
            <p>
                <label>
                    Staff Name:</label>
                <asp:TextBox ID="txtStaffName" runat="server" Enabled="false" />
            </p>
            <p>
                <label>
                    Unit Name</label>
                <asp:TextBox ID="txtUnitName" runat="server" Enabled="false" />
            </p>
            <p>
                <label>
                    Staff Type</label>
                <asp:TextBox ID="txtStaffType" runat="server" Enabled="false" />
            </p>
            <p>
                <label>
                    Staff Level</label>
                <asp:TextBox ID="txtStaffLevel" runat="server" Enabled="false" />
            </p>
            <p class="submitButton" style="text-align: center">
                <asp:Button ID="btnOk" runat="server" Text=" OK " ValidationGroup="RegisterUserValidationGroup"
                    CssClass="btn" OnClick="btnOk_Click" OnClientClick="return CheckFullInfor();" />
                <asp:Button ID="btnCancel" runat="server" Text="Cancel" CssClass="btn" OnClick="btnCancel_Click" />
            </p>
        </div>
    </div>
    <asp:Panel ID="pnlGrantPrivileges" runat="server" CssClass="span8">
        <div class="row-fluid">
            <div class="head">
                <div class="isw-grid">
                </div>
                <h1>
                    Member of Groups</h1>
                <asp:HiddenField ID="hdfTreeID" Value="" runat="server" />
                <input type="hidden" id="checkAdd" value="add" />
                <div class="clear">
                </div>
            </div>
            <div class="block-fluid">
                <table width="100%" cellspacing="0" cellpadding="0" id="Table1" class="table">
                    <thead>
                        <tr>
                            <th style="width: 35px">
                                No
                            </th>
                            <th style="width: 190px">
                                Group Name
                            </th>
                            <th>
                                Description
                            </th>
                            <th style="width: 35px">
                                &nbsp;
                            </th>
                        </tr>
                    </thead>
                    <tbody>
                        <asp:Repeater ID="rptGroup" runat="server">
                            <ItemTemplate>
                                <tr>
                                    <td align="center">
                                        <%#(Container.ItemIndex +1) %>
                                        <asp:HiddenField ID="hdfGroup" runat="server" Value='<%#Eval("GroupID")%>' />
                                    </td>
                                    <td>
                                        <%#Eval("GroupName")%>
                                    </td>
                                    <td>
                                        <%#Eval("Description")%>
                                    </td>
                                    <td align="center">
                                        <asp:CheckBox ID="chkCheck" runat="server" Checked='<%#Eval("Checked")%>' />
                                    </td>
                                </tr>
                            </ItemTemplate>
                        </asp:Repeater>
                    </tbody>
                </table>
            </div>
            <div class="clear">
            </div>
            <div class="head">
                <div class="isw-grid">
                </div>
                <h1>
                    Added Roles</h1>
                <div class="clear">
                </div>
            </div>
            <div class="block-fluid">
                <table width="100%" cellspacing="0" cellpadding="0" id="tbRole" class="table">
                    <thead>
                        <tr>
                            <th style="width: 35px">
                                No
                            </th>
                            <th style="width: 190px">
                                Role Name
                            </th>
                            <th>
                                Description
                            </th>
                            <th style="width: 35px">
                                &nbsp;
                            </th>
                        </tr>
                    </thead>
                    <tbody>
                        <asp:Repeater ID="rptRole" runat="server">
                            <ItemTemplate>
                                <tr>
                                    <td align="center">
                                        <%#(Container.ItemIndex +1) %>
                                        <asp:HiddenField ID="hdfRole" runat="server" Value='<%#Eval("RoleId")%>' />
                                    </td>
                                    <td>
                                        <%#Eval("RoleName")%>
                                    </td>
                                    <td>
                                        <%#Eval("Description")%>
                                    </td>
                                    <td align="center">
                                        <asp:CheckBox ID="chkCheck" runat="server" Checked='<%#Eval("Checked")%>' />
                                    </td>
                                </tr>
                            </ItemTemplate>
                        </asp:Repeater>
                    </tbody>
                </table>
            </div>
        </div>
    </asp:Panel>
    <input type="hidden" id="formId" value="UserManagement" />
</asp:Content>
